app.controller('bpmManagerProcessinstanceController', ['$scope', 'httpWrapService', 'dialogs', '$state', '$stateParams','AppConstants','TableFactory',
        function($scope, httpWrapService, dialogs, $state, $stateParams,AppConstants, TableFactory) {

	$scope.params = {};
	var processInstanceId = $scope.params.processInstanceId = {
			field : 'processInstanceId',
			type : AppConstants.filter.CONTAINS,
			term : ''
	};
	
    $scope.Table1 = TableFactory.newInstance({
		url : 'bpm/processinstance/list.do',
		params : [processInstanceId]
	});
    $scope.Table1.load();



    $scope.changeState = function(row) {
        var id = row.id;
        var state = row.suspended ?  'active' : 'suspended';
        httpWrapService.defaultFootTableDelete($scope.Table1, id, 'bpm/processinstance/'+ state + '/' + id +'.do', {},'是否确定删除？').then(function(){
        	$scope.Table1.load();
        });
    };


    $scope.delete = function(id) {
        var dlg = dialogs.create('tpl-common\/inputDialog.html','inputDialogCtrl',{title : '请输入删除原因'},{size:'md',keyboard: true,backdrop: true,windowClass: 'my-class'});
        dlg.result.then(function(deleteReason){
            httpWrapService.post('bpm/processinstance/delete/'+ id +'.do', {
                deleteReason : deleteReason
            }).then(function(){
            	$scope.Table1.load();
            }, function(){
                dialogs.notify('错误', '删除失败', {size : 'sm'});
            });
        },function(){
        });
    };
}]);

/**
 */
app.filter('bpmManagerProcessDefinitionFilter', ["$sessionStorage", "httpWrapService","customObjectFilterFactory", function($sessionStorage, httpWrapService, customObjectFilterFactory) {
    return function(input, filed){
        return customObjectFilterFactory.newInstance({
            param : {},
            getUrl : function(intput, filed){
                return 'bpm/processinstance/view/' +input+ '.do';
            },
            getKey : function(intput, filed){
                return 'bpmManagerProcessDefinitionFilter_' + input;
            }
        }).filter(input, filed);
    };
}]);
